/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package inet.dao;

import inet.entity.TimeKeeping;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import inet.ulti.DateTimeUlti;
import java.math.BigDecimal;

/**
 *
 * @author ÂuNgọcThái
 */
public class TimeKeepingDAO extends BaseDAO {

    

    public List<TimeKeeping> getAll() {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = null;
        List<TimeKeeping> lstTimeKeep = null;
        try {
            sql = "SELECT * FROM TIMEKEEPING";
            conn = getConnection();
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            TimeKeeping timekeep = null;
            while (rs.next()) {
                timekeep = new TimeKeeping();
                if (lstTimeKeep == null) {
                    lstTimeKeep = new ArrayList<TimeKeeping>();
                }
                int i = 1;
                timekeep.setEmp_id(rs.getBigDecimal(i++));
                timekeep.setTk_name(rs.getString(i++));
                timekeep.setTk_id(rs.getBigDecimal(i++));
                lstTimeKeep.add(timekeep);
            }
            return lstTimeKeep;
        } catch (Exception ex) {
            System.out.println("Error in sql: " + sql);
            ex.printStackTrace();
        } finally {
            releaseConnection(conn, ps, rs);
        }
        return null;
    }

    public BigDecimal getID(BigDecimal id) {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = null;
        try {
            sql = "SELECT TK_ID FROM TIMEKEEPING WHERE EMP_ID=? AND TK_NAME=?";
            conn = getConnection();
            ps = conn.prepareStatement(sql);
            ps.setBigDecimal(1, id);
            ps.setString(2, DateTimeUlti.noteDate());
            rs = ps.executeQuery();
            int i = 1;
            if (rs.next()) {
                return rs.getBigDecimal(1);
            }
        } catch (Exception ex) {
            System.out.println("Error in sql: " + sql);
            ex.printStackTrace();
        } finally {
            releaseConnection(conn, ps, rs);
        }
        return null;
    }

}
